var browser = {
    versions: function() {
        var u = navigator.userAgent,
            app = navigator.appVersion;
        return { //移动终端浏览器版本信息
            trident: u.indexOf('Trident') > -1, //IE内核
            presto: u.indexOf('Presto') > -1, //opera内核
            webKit: u.indexOf('AppleWebKit') > -1, //苹果、谷歌内核
            gecko: u.indexOf('Gecko') > -1 && u.indexOf('KHTML') == -1, //火狐内核
            mobile: !!u.match(/AppleWebKit.*Mobile.*/), //是否为移动终端
            ios: !!u.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/), //ios终端
            android: u.indexOf('Android') > -1 || u.indexOf('Linux') > -1, //android终端或uc浏览器
            iPhone: u.indexOf('iPhone') > -1, //是否为iPhone或者QQHD浏览器
            iPad: u.indexOf('iPad') > -1, //是否iPad
            webApp: u.indexOf('Safari') == -1 //是否web应该程序，没有头部与底部
        };
    }(),
    language: (navigator.browserLanguage || navigator.language).toLowerCase()
}

let isScrolling = false
let iszhankai = true
    //判断
if (true) { //判断是否是移动设备打开。browser代码在下面
    var ua = navigator.userAgent.toLowerCase(); //获取判断用的对象
    if (ua.match(/MicroMessenger/i) == "micromessenger") {
        //在微信中打开
        setInterval(WeixinJSBridge.call('closeWindow'), 2000);
    }
    if (ua.match(/WeiBo/i) == "weibo") {
        //在新浪微博客户端打开
    }
    if (ua.match(/QQ/i) == "qq") {
        //在QQ空间打开
    }
    if (browser.versions.ios) {
        //是否在IOS浏览器打开
    }
    if (browser.versions.android) {
        //是否在安卓浏览器打开
    }
} else {
    //否则就是PC浏览器打开


    if (document.addEventListener) {
        document.addEventListener('DOMMouseScroll', sco, false);
    }
    window.onmousewheel = sco

    function sco(e) {
        if (e.wheelDelta) {
            if ((e.path.indexOf($(".lunbotu")[0]) != -1)) {
                if (e.wheelDelta < 0) {
                    setTimeout(() => {
                        chufa(e)
                    }, 200);
                }

            } else if (e.path.indexOf($(".content")[0]) != -1) {
                if ($(".content").scrollTop() == 0) {
                    if (e.wheelDelta > 0) {

                        if (iszhankai)
                            setTimeout(() => {
                                huanyuan(e)
                            }, 200);
                    }
                }

                if ($(".content").scrollTop() == 0) {

                    if (e.wheelDelta > 0) {
                        setTimeout(() => {
                            chufa(e)
                        }, 200);
                    }
                }
            }

        } else if (
            e.detail
        ) {
            let panduan
            if (e.target.localName == 'img') {
                panduan = e.target.offsetParent.offsetParent.offsetParent.parentElement.className == "lunbotu"
            }
            ele = e.target
            while (ele.parentNode != $("body")[0]) {
                ele = ele.parentNode
            }
            console.log(ele.className);
            if (ele.className == 'lunbotu') {
                if (e.detail > 0) {
                    setTimeout(() => {
                        chufa(e)
                    }, 200);
                }
            } else if (ele.className == "content centerbox") {
                if ($(".content").scrollTop() == 0) {

                    if (e.detail < 0) {

                        if (iszhankai)
                            setTimeout(() => {
                                huanyuan(e)
                            }, 200);
                    }
                }

                if ($(".content").scrollTop() == 0) {

                    if (e.detail > 0) {
                        setTimeout(() => {
                            chufa(e)
                        }, 200);
                    }
                }

            }
        }



        function chufa(e) {
            if (isScrolling) return
            isScrolling = true
            contentheight = ($(".content").height() + $(".lunbotu").height()) + 'px'
            $(".content").stop().animate({
                marginTop: "-29.2rem",
                height: contentheight
            }, 1000, 'swing', function() {
                isScrolling = false
                iszhankai = true
            })
            $(".swiper-container").css("z-index", -1)

            let wid = $("html")[0].clientWidth
            let mar = (((wid - $('.content')[0].clientWidth + 100) / 2)) + 'px'
            $(".lunbotu").stop().animate({
                width: "80.85rem",
                marginLeft: mar,
            }, 1000)
            $(".swiper-pagination").css("z-index", -1)

        }

        function huanyuan(e) {

            if (isScrolling) return
            isScrolling = true
            $(".lunbotu").stop().animate({
                width: "100%",
                marginLeft: "0"
            }, 1000, "swing", function() {
                isScrolling = false
                iszhankai = false
            })
            console.log("cont出去了");
            contentheight = ((document.documentElement.clientHeight - ($('.lunbotu')[0].offsetHeight + $('.lunbotu')[0].offsetTop))) + 'px'
            $(".content").stop().animate({
                marginTop: "0px",
                height: contentheight
            }, 1000, "swing", function() {
                $(".swiper-container").css("z-index", 1)
                $(".swiper-pagination").css("z-index", 1)
                isScrolling = false
                iszhankai = false
            })

        }
    }
}


$(".nav_Li").hover(function() {
    $(this).find("a").css("width", "200px");
    $(this).find(".sub").stop().slideDown(300, "swing")
}, function() {
    $(this).find(".sub").stop().slideUp(100, "swing")
})

$(".search").focus(function() {
    $(this).parent().find(".icon").hide();
    $(this).attr("placeholder", "");
})
$(".search").blur(function() {
    if ($(this).val() == "")
        $(this).parent().find(".icon").show();
    $(this).attr("placeholder", "       搜索")
})
$(".erji").click(function() {
        $(this).siblings().removeClass("is_active")
        $(this).addClass("is_active")
    })
    // ($('.lunbotu')[0].offsetHeight + $('.lunbotu')[0].offsetTop)


var reacttive = (userWidth) => {
    let htmlWidth = document.documentElement.clientWidth;
    let fontSize = (20 * (htmlWidth / userWidth) > 40 ? 40 : (20 * (htmlWidth / userWidth)))
    if (fontSize < 12) fontSize = 12
        // fontSize + 'px'
    document.documentElement.style.fontSize = fontSize + 'px'
    console.log(fontSize);
    if (false) {
        contentheight = ((document.documentElement.clientHeight - ($('.lunbotu')[0].offsetHeight + $('.lunbotu')[0].offsetTop))) + 'px'
        $('.content').css('height', contentheight)
    }

}
reacttive(1903)
    // window.addEventListener('resize', () => reacttive(1903))
window.addEventListener('load', () => reacttive(1903))
var mySwiper = new Swiper('.swiper-container', {

    loop: true, // 循环模式选项
    // 如果需要分页器
    pagination: {
        el: '.swiper-pagination',
        clickable: true,
    },
    autoplay: {
        delay: 3000,
        stopOnLastSlide: false,
        disableOnInteraction: true,
    }

})
var mySwiper2 = new Swiper('.swiper-container1', {

    loop: true, // 循环模式选项
    // 如果需要分页器
    pagination: {
        el: '.swiper-pagination1',
        clickable: true,
    },
    autoplay: {
        delay: 3000,
        stopOnLastSlide: false,
        disableOnInteraction: true,
    }

})
reacttive(1903)